package com.sky.financelake.viewmodels.local;

import android.content.Context;
import android.util.Log;

import androidx.lifecycle.MutableLiveData;

import com.sky.financelake.bean.dao.DBManager;
import com.sky.financelake.bean.db.Combination;
import com.sky.financelake.viewmodels.BaseViewModel;

import java.util.ArrayList;
import java.util.List;

public class CombinationViewModel extends BaseViewModel {

    private MutableLiveData<List<String>> mutableLiveData;

    public MutableLiveData<List<String>> getCombinationsLiveData(Context context) {
        if (mutableLiveData == null) {
            mutableLiveData = new MutableLiveData<List<String>>();
        }
        return mutableLiveData;
    }

    public void getCombinations(Context context)  {
        try {
            List<Combination> combinations = DBManager.getInstance(context).queryCombinationList();
            List<String> str = new ArrayList<>();
            for (Combination c : combinations) {
                str.add(c.getValue());
            }
            mutableLiveData.setValue(str);
        }catch (Exception e){
            Log.i(TAG, "getCombinations: "+e.getLocalizedMessage());
        }

    }

    public void insertCombinations(Context context, Combination combination) throws Exception {
        DBManager.getInstance(context).insertCombination(combination);
    }
}
